package com.example.gustavo.hello.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.text.TextUtils;
import android.text.format.Formatter;

import com.example.gustavo.hello.MyApplication;

import java.io.File;

public class DownLoadReceiver extends BroadcastReceiver {
    public DownLoadReceiver() {
    }

    @Override
    public void onReceive(Context context, Intent intent) {

        System.out.println("receive ================ " + MyApplication.downLoadFile);
        if(!TextUtils.isEmpty(MyApplication.downLoadFile)){

            File file = new File(MyApplication.downLoadFile);
            boolean exists = file.exists();
            System.out.println("exists = " + exists);
            String fileSize = Formatter.formatFileSize(context, file.length());
            System.out.println("fileSize = " + fileSize);


            PackageInfo archiveInfo = context.getPackageManager().getPackageArchiveInfo(MyApplication.downLoadFile, PackageManager.GET_ACTIVITIES);

            String packageName = archiveInfo.packageName;
            System.out.println("packageName = " + packageName);
        }



    }
}
